package main

import (
	"fmt"
	"net"
)


func read(conn net.Conn){

	defer conn.Close()
	for{

		msg:=make([]byte,1024)

		n,err:=conn.Read(msg)

		if err!=nil{
			fmt.Printf("read error =%v\n",err)
			return
		}else{

			fmt.Printf("recv data=%v\n",string(msg[:n]))

			conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 11\r\n\r\nhello,world"))
		}
	}
}


func main(){


	Listener, error:=net.Listen("tcp","0.0.0.0:9501")

	if error!=nil{
		fmt.Printf("listen error =%v\n",error)
	}
	defer Listener.Close()
	for {

		Conn, error:=Listener.Accept()
		if error!=nil{
			fmt.Printf("accept error=%v\n",error)
		}

		go read(Conn)
	}
}
